﻿function getDocProperty(str) {
    var result = 0;
    switch (str) {
        case "scrollTop":
            if (typeof (window.pageYOffset) != 'undefined') {
                result = window.pageYOffset
            } else if (typeof (document.compatMode) != 'undefined' && document.compatMode != 'BackCompat') {
                result = document.documentElement.scrollTop
            } else if (typeof (document.body) != 'undefined') {
                result = document.body.scrollTop
            }
            break;
        case "clientWidth":
            if (typeof (document.compatMode) != 'undefined' && document.compatMode != 'BackCompat') {
                result = document.documentElement.clientWidth
            } else if (typeof (document.body) != 'undefined') {
                result = document.body.clientWidth
            }
            break;
        case "clientHeight":
            if (typeof (document.compatMode) != 'undefined' && document.compatMode != 'BackCompat') {
                result = document.documentElement.clientHeight
            } else if (typeof (document.body) != 'undefined') {
                result = document.body.clientHeight
            }
            break;
        case "scrollWidth":
            if (typeof (document.compatMode) != 'undefined' && document.compatMode != 'BackCompat') {
                result = document.documentElement.scrollWidth
            } else if (typeof (document.body) != 'undefined') {
                result = document.body.scrollWidth
            }
            break;
        case "scrollHeight":
            if (typeof (document.compatMode) != 'undefined' && document.compatMode != 'BackCompat') {
                result = document.documentElement.scrollHeight
            } else if (typeof (document.body) != 'undefined') {
                result = document.body.scrollHeight
            }
            break;
        default:
            break
    }
    return result
};
if(!window.ZHAO){
    var ZHAO={};
    ZHAO.Dialog={
        docEl:document.documentElement,
        isInit:false,
        id:'dialog',
        className:'popdiv',
        style:'',
        innerHTML:'',
        Constructor:function(){
            var popdiv,
                objOld=this.$$(this.id);
            if(objOld) objOld.parentNode.removeChild(objOld);
            try
            {                
                //if(!this.isInit){
                    var docBody=document.body;
                    var mark=this.$$('mark');
                    var ch=getDocProperty('clientHeight'),
                        ch2=getDocProperty('scrollHeight');
                    if(!mark){
                        mark=document.createElement('div');
                        mark.id='mark';
                        mark.innerHTML='<iframe src="" frameborder="0"></iframe>';
                        docBody.insertBefore(mark,docBody.childNodes[0]);
                    }
	                
	                mark.style.height=(ch2>ch?ch2:ch)+'px';
	                mark.style.left=0+'px';
    	            mark.style.filter='alpha(opacity=0)';
    	            mark.style.opacity=0;
	            
                    popdiv=document.createElement('div');
                    popdiv.id=this.id;
                    popdiv.className=this.className;
                    popdiv.innerHTML=this.innerHTML;
                    if(window.ActiveXObject)
                        popdiv.style.cssText=this.style;
                    else
                        popdiv.setAttribute('style',this.style);
                    //docBody.insertBefore(popdiv,docBody.childNodes[0]);
                    document.body.appendChild(popdiv);                    
                    this.isInit=true;
                //}
            }catch(e){
                popdiv=null;
            }
        },
        Open:function(){
            this.Constructor();
            this.disDiv(this.id);
        },
        
        Close:function(){
            this.undisDiv();
            return false;
        },
        
        undisDiv:function(){
            var mark=this.$$("mark");
            var obj=this.$$(this.id);
            if(obj)
            {
	            obj.style.display='none';        
                mark.style.display='none';
                mark.style.height=0+'px';
            }
            return;
        },
        
        disDiv:function(obj){
            messageSender=obj;
            var ct=getDocProperty('scrollTop'),
                cw=getDocProperty('scrollWidth'),
                ch=getDocProperty('clientHeight');
            var mark=$$('mark'),
                message=(typeof obj=='object')?obj:this.$$(obj);
	        (arguments[1]!=null&&arguments[2]!=null)?(eval(arguments[2]).location.href=arguments[1]):'';
       	        
       	    mark.style.display='block';
	        message.style.display='block';
	        
	        message.style.top=ct+(ch-message.clientHeight)/2+'px';
	        message.style.left=(cw-message.clientWidth)/2+'px';
	        document.onmousedown=this.click;
        	this.changeWindow();
        },
        
        click:function(){
	        if(window.event.button==1||window.event.button==2){return false;}
        },

        changeWindow:function(){
	        var message=(typeof messageSender=='object')?messageSender:document.getElementById(messageSender),
	            cw=getDocProperty('scrollWidth'),
	            ch=getDocProperty('clientHeight'),
	            ch2=getDocProperty('scrollHeight');
	        message.style.top=getDocProperty('scrollTop')+(ch-message.clientHeight)/2+'px';
	        message.style.left=(cw-message.clientWidth)/2+'px';

	        window.setTimeout(ZHAO.Dialog.changeWindow,50);
        },
        
        $$:function(id){
            return document.getElementById(id);
        }
    };
}